<?php
$websiteId = $this->getRequest()->getParam('website_id');
$storeId = Mage::getModel('core/website')->load($websiteId)->getStoreCollection()->getFirstItem();
$productId = $this->getRequest()->getParam('product_id');
$product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId);
Mage::register('product', $product);
$k3_info = $this->K3cloud_data();
$add_websiteid = array(11,20,21,22,19);
?>

<div class="entry-edit">
    <div class="entry-edit-head">
    <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $product->getName(); ?>出入库记录</h4>
    <div class="form-buttons"></div>
</div>
    <div class="fieldset  ignore-validate" id="coupons_information_fieldset">
    <div class="hor-scroll">
    <table cellspacing="0" class="form-list">
        <tbody>
            <tr>
        		<td colspan="2" class="hidden">
        			<input id="product_id" name="product_id" value="<?php echo $product->getId()?>" type="hidden" class=""/>
        			<input id="website_id" name="website_id" value="<?php echo $this->getRequest()->getParam('website_id');?>" type="hidden" class="">
        		</td>
    		</tr>
    		<tr>
			    <td class="label"><label for="qty">当前库存</label></td>
			    <td class="value">
			        <?php echo intval($product->getStockItem()->getQty());?>
			    </td>
    		</tr>
    		<tr>
        		<td class="label"><label for="operation">操作<span class="required">*</span></label></td>
    			<td class="value">
				<?php if(in_array($websiteId, $add_websiteid)):?>
	        		<select id="operation" onchange="changeValue()" name="operation" class="required-entry select">
	        		<option value="1" id="Checkbox1" >入库</option>
					<option value="2" id="Checkbox2" >出库</option>
					<option value="3" id="Checkbox3" >退货</option>
					</select>
				<?php else:?>
					<select id="operation"  name="operation" class="required-entry select">
					<option value="1" id="Checkbox1" >入库</option>
					<option value="2" id="Checkbox2" >出库</option>
					</select>
				 <?php endif;?>
				</td>
    		</tr>
			<tr>
			    <td class="label"><label for="qty">数量</label></td>
			    <td class="value">
			        <input id="qty" name="qty" value="0" title="Dash Every X Characters" class="validate-digits input-text" type="text">
					<p class="note" id="note_dash"><span>出入库数量</span></p>
			    </td>
    		</tr>
    		<!-- add by wanglin start -->
			<?php if(in_array($websiteId, $add_websiteid)):?>
    		<tr>
        		<td class="label"><label for="operation">部门<span class="required">*</span></label></td>
    			<td class="value">
	        		<select id="FDEPTID" name="FDEPTID" class="required-entry select">
	        		<option value=""></option>
	        		 <?php foreach($k3_info['FDEPTID'] as $FDEPTID):?>
                   		<option value="<?php echo $FDEPTID->FNumber;?>"><?php echo $FDEPTID->FName; ?></option>
               		 <?php endforeach;?>
					</select>
				</td>
    		</tr>
    		<tr>
        		<td class="label"><label for="operation">验收员<span class="required">*</span></label></td>
    			<td class="value">
	        		<select id="FACCEPTANCE" name="FACCEPTANCE" class="required-entry select">
	        		<option value=""></option>
					<?php foreach($k3_info['FACCEPTANCE'] as $FDEPTID):?>
                   		<option value="<?php echo $FDEPTID->FNumber;?>"><?php echo $FDEPTID->FName; ?></option>
               		 <?php endforeach;?>
					</select>
				</td>
    		</tr>
    		
    		<tr id="qtrkyt">
        		<td class="label"><label for="operation">其它入库用途<span class="required">*</span></label></td>
    			<td class="value">
	        		<select id="FQTRK_TYPE" name="FQTRK_TYPE" class="required-entry select">
	        		<option value=""></option>
					<?php foreach($k3_info['FQTRK_TYPE_in'] as $FDEPTID):?>
                   		<option value="<?php echo $FDEPTID->FNumber;?>"><?php echo $FDEPTID->FDataValue; ?></option>
               		 <?php endforeach;?>
					</select>
				</td>
    		</tr>
    		<tr id="qtckyt" style="display:none">
        		<td class="label"><label for="operation">用途<span class="required">*</span></label></td>
    			<td class="value">
	        		<select id="FQTRK_TYPE_out" name="FQTRK_TYPE_out" class="">
	        		<option value=""></option>
					<?php foreach($k3_info['FQTRK_TYPE_out'] as $FDEPTID):?>
                   		<option value="<?php echo $FDEPTID->FNumber;?>"><?php echo $FDEPTID->FDataValue; ?></option>
               		 <?php endforeach;?>
					</select>
				</td>
    		</tr>
    		<tr>
        		<td class="label"><label for="operation">供应商</label></td>
    			<td class="value">
	        		<select id="FSUPPLIERID" name="FSUPPLIERID">
	        		<option value=""></option>
					<?php foreach($k3_info['FSUPPLIERID'] as $FDEPTID):?>
                   		<option value="<?php echo $FDEPTID->FNumber;?>"><?php echo $FDEPTID->FName; ?></option>
               		 <?php endforeach;?>
					</select>
				</td>
    		</tr>
    		 <?php endif;?>
    		<!-- add by wanglin end -->
    		
    		<tr>
			    <td class="label"><label for="comment">备注</label></td>
			    <td class="value">
			        <textarea name="comment" class="required-entry" cols="15" rows="2" style="height:100px"></textarea><p class="note" id="note_dash"><span>备注信息</span></p>
			    </td>
    		</tr>
			<tr>
        		<td class="label"></td>
			    <td class="value">
			        <span id="coupons_generate_button"><button id="id_3cf81872242ced1ce5317b5704e032c7" title="保存" type="button" class="scalable generate" onclick="generateCouponCodes('coupons_' ,'<?php echo $this->getUrl('admin_zgb/adminhtml_inventory/update');?>', 'newGridJsObject')" style=""><span><span><span>保存</span></span></span></button></span>
			    </td>
    		</tr>
        </tbody>
    </table>
    </div>
    </div>
</div>
<script type="text/javascript"> 
	function changeValue(){
		var myselect = document.getElementById("operation");
		var index = myselect.selectedIndex ;
		var value = myselect.options[index].value;
		if(parseInt(value)== 2 || parseInt(value)== 3){
			document.getElementById("qtckyt").style.display = "";
			document.getElementById("qtrkyt").style.display = "none";
			document.getElementById("FQTRK_TYPE_out").className = "required-entry select";
			document.getElementById("FQTRK_TYPE").className 	= "select";
	    }else{
	    	document.getElementById("qtckyt").style.display = "none";
			document.getElementById("qtrkyt").style.display = "";
			document.getElementById("FQTRK_TYPE_out").className = "select";
			document.getElementById("FQTRK_TYPE").className = "required-entry select";
		}
	
	}
	function generateCouponCodes(idPrefix, generateUrl, grid) {
	    $(idPrefix + 'information_fieldset').removeClassName('ignore-validate');
	    var validationResult = $(idPrefix + 'information_fieldset').select('input',
	            'select', 'textarea').collect( function(elm) {
	        return Validation.validate(elm, {
	            useTitle :false,
	            onElementValidate : function() {
	            }
	        });
	    }).all();
	    $(idPrefix + 'information_fieldset').addClassName('ignore-validate');

	    if (!validationResult) {
	        return;
	    }
	    var elements = $(idPrefix + 'information_fieldset').select('input', 'select', 'textarea');

	    elements = elements.concat(
	        $$('#rule_uses_per_coupon'),
	        $$('#rule_uses_per_customer'),
	        $$('#rule_to_date')
	    );

	    var params = Form.serializeElements(elements, true);
	    params.form_key = FORM_KEY;
	    $('messages').update();
	    var couponCodesGrid = eval(grid);
	    new Ajax.Request(generateUrl, {
	        parameters :params,
	        method :'post',
	        onComplete : function (transport, param){
	            var response = false;
	            if (transport && transport.responseText) {
	                response = eval('(' + transport.responseText + ')');
	            }
	            
	            if (couponCodesGrid) {
	                couponCodesGrid.reload();
	            }
	            if (response && response.messages) {
	                $('messages').update(response.messages);
	            }
	            if (response && response.error) {
		            if(response.message == '成功'){
		            	alert(response.message);
		            	location.reload();
			        }else{
			        	alert(response.message);
				    }
	            }
	        }
	    });
	}
</script>
<?php echo $this->getLayout()->createBlock('zgb/adminhtml_inventory_new_grid')->toHtml(); ?>